#include "StdAfx.h"
#include "GroupInfo.h"
#include "../TestNumber/TestNumber.h"
GroupInfo::GroupInfo(void)
{
}

GroupInfo::~GroupInfo(void)
{
	SAFE_DELETE(InitTestNumber);
}

GroupInfo* GroupInfo::Create( UINT TestId,CMarkup& xml )
{
	CString Description	= xml.GetAttrib(_T("Description"));	

	CString strInitTestNumber = xml.GetAttrib(_T("InitTestNumber"));	
	std::auto_ptr<TestNumber> pTestNumber(TestNumber::Create(TestId,strInitTestNumber));
	if(pTestNumber.get() == NULL)
		return NULL;
	
	CString AudioDestination = xml.GetAttrib(_T("AudioDestination"));	
	
	COLORREF TextColor = RGB(0,0,0);
	{ 
		int	r =	0; 
		int	g =	0; 
		int	b =	0; 

		CString	strColor= xml.GetAttrib(_T("TextColor"));	
		if(!strColor.IsEmpty())	
			sscanf(strColor,_T("RGB(%d,%d,%d)"),&r,&g,&b); 
		TextColor = RGB(r,g,b); 
	} 
	
	CString Language = xml.GetAttrib(_T("Language"));	

	GroupInfo* newGroup = new GroupInfo;
	newGroup->Description = Description;
	newGroup->InitTestNumber = pTestNumber->Clone();
	newGroup->AudioDestination = AudioDestination;
	newGroup->TextColor = TextColor;
	newGroup->Language = Language;
	return newGroup;
}

BOOL GroupInfo::Save( CMarkup& xml )
{
	xml.AddElem(_T("GroupInfo"));

	xml.AddAttrib(_T("Description"),Description);

	*InitTestNumber += 1000;
	xml.AddAttrib(_T("InitTestNumber"),InitTestNumber->GetString());

	xml.AddAttrib(_T("AudioDestination"),AudioDestination);

	{
		int r = GetRValue(TextColor);
		int g = GetGValue(TextColor);
		int b = GetBValue(TextColor);
		CString strColor;
		strColor.Format("RGB(%d,%d,%d)",r,g,b);
		xml.AddAttrib(_T("TextColor"),strColor);
	}

	xml.AddAttrib(_T("Language"),Language);
	
	return true;
}